/* Global styles and responsive design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Main container - responsive height based on iframe/standalone */
#main-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: grid;
    grid-template-columns: 250px 1fr 200px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "controls simulation data"
        "controls simulation data"
        "education education education";
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Detect if running in standalone mode */
@media (min-height: 500px) {
    #main-container {
        height: 90vh;
    }
}

/* Control Panel Styles */
#control-panel {
    grid-area: controls;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #2c3e50;
    font-size: 12px;
}

.control-group select,
.control-group input[type="range"] {
    width: 100%;
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 5px;
    font-size: 12px;
    transition: border-color 0.3s ease;
}

.control-group select:focus,
.control-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Button styles optimized for touch */
button {
    width: 100%;
    padding: 12px 8px;
    margin: 5px 0;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px; /* Touch-friendly minimum */
}

#start-btn {
    background: linear-gradient(45deg, #28a745, #20c997);
    color: white;
}

#pause-btn {
    background: linear-gradient(45deg, #ffc107, #fd7e14);
    color: white;
}

#reset-btn {
    background: linear-gradient(45deg, #dc3545, #e83e8c);
    color: white;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
}

/* Simulation Area Styles */
#simulation-area {
    grid-area: simulation;
    background: #ffffff;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#environment-display {
    background: linear-gradient(45deg, #4CAF50, #8BC34A);
    color: white;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    text-align: center;
}

#env-title {
    font-size: 14px;
    margin-bottom: 5px;
}

#env-description {
    font-size: 11px;
    opacity: 0.9;
}

#population-container {
    flex: 1;
    overflow: hidden;
}

#generation-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 11px;
    color: #6c757d;
}

/* Organism grid for population display */
#organism-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(25px, 1fr));
    gap: 3px;
    height: calc(100% - 30px);
    overflow-y: auto;
}

.organism {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    border: 2px solid #333;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.organism:hover {
    transform: scale(1.2);
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.organism.dead {
    opacity: 0.3;
    filter: grayscale(100%);
}

.organism.selected {
    border-color: #667eea;
    border-width: 3px;
}

/* Data Panel Styles */
#data-panel {
    grid-area: data;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.chart-container h4,
.stats-container h4 {
    font-size: 12px;
    color: #2c3e50;
    margin-bottom: 10px;
    text-align: center;
}

#trait-chart {
    width: 100%;
    height: 120px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
}

.stats-container {
    margin-top: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
}

.stat-label {
    color: #6c757d;
}

/* Education Panel Styles */
#education-panel {
    grid-area: education;
    background: #e9ecef;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.concept-box h4 {
    font-size: 12px;
    color: #2c3e50;
    margin-bottom: 10px;
    text-align: center;
}

.concept-item {
    margin-bottom: 10px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.concept-item:hover {
    background-color: rgba(102, 126, 234, 0.1);
}

.concept-term {
    font-weight: 600;
    font-size: 11px;
    color: #495057;
    display: block;
}

.concept-definition {
    font-size: 10px;
    color: #6c757d;
    margin-top: 4px;
    display: none;
}

.concept-item.active .concept-definition {
    display: block;
}

/* Tooltip Styles */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 200px;
    text-align: center;
}

.tooltip.show {
    opacity: 1;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

/* Environment-specific styles */
.environment-forest {
    background: linear-gradient(45deg, #4CAF50, #8BC34A);
}

.environment-desert {
    background: linear-gradient(45deg, #FF9800, #FFC107);
}

.environment-arctic {
    background: linear-gradient(45deg, #2196F3, #03DAC6);
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    #main-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas: 
            "controls"
            "data"
            "simulation"
            "education";
        height: 90vh;
    }
    
    #control-panel {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .control-group {
        flex: 1;
        min-width: 120px;
        margin-bottom: 0;
    }
    
    button {
        padding: 10px 6px;
        font-size: 11px;
    }
    
    #organism-grid {
        grid-template-columns: repeat(auto-fit, minmax(20px, 1fr));
    }
    
    .organism {
        width: 20px;
        height: 20px;
    }
}

/* High contrast mode for accessibility */
@media (prefers-contrast: high) {
    #main-container {
        background: white;
        border: 2px solid black;
    }
    
    .organism {
        border-width: 3px;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}